<!DOCTYPE html>
<html lang="en" style="height:100%">

<head>
	<meta charset="UTF-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="teleemail=no,email=no,date=no,address=no">
	<title>找回密码</title>
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/style.css" />
	<link rel="stylesheet" type="text/css" href="../../css/yzl.css" />
	<link rel="stylesheet" href="../../css/sqc.css">
	<style>
		.active {
			font-weight: 800;
			border-bottom: 2px solid #33375E;
		}

		.sendcode {
			background: #ccc;
		}

		.sendactive {
			background: #f7be3d;

		}

		.input {
			border-radius: 5px;
			line-height: 40px;
		}

		[v-cloak] {
			display: none
		}
	</style>
</head>

<body style="background: white;">
	<div id="blank" class="header" v-cloak>
		<div v-back.tapmode class="back"></div>
		

	</div>
	<div class="login1" id="app" v-cloak>
		<div class="select-box">
			<span class="select-title select-title-text" >找回密码</span>
			<span style="display: inline-block; width: 10px;"></span>
			<!-- 验证码登录 -->
			<div class="code-box">

				<div class="warn-box clearfix">
					<span class="warn-title-left">请输入邮箱</span>
					<span class="warn-title-right" v-show="warn">{{warnText1}}</span>
					<input class="input" style="padding:1rem 5px;line-height:1.6rem"  v-model="email" ref="input1" placeholder="" required />
				</div>
				<div class="warn-box clearfix" style="margin-top:20px;">
					<span class="warn-title-left">请输入新密码</span>
					<span class="warn-title-right" v-show="warn">{{warnText3}}</span>
					<input class="input" type="password" v-model="password" ref="input1" style="padding:1rem 5px;line-height:1.6rem" placeholder="" required />
				</div>
				<!-- line-height:3.6rem -->
				<div class="warn-box clearfix " style="margin-top:20px;position:relative">
					<span class="warn-title-left">请输入验证码</span>
					<span class="warn-title-right" v-show="warn">{{warnText2}}</span>
					<input type="number" class="getcodecontent input-text" v-model="code" oninput="if(value.length>6)value=value.slice(0,6)" style="padding:1rem 5px;line-height:1.6rem;width: 100%;" />
					<sendcode @codemessage="codeMessage" :email="email" type="2" style="position:absolute;right:0px;top:2.8rem">
					</sendcode>
				</div>
				<div class="input-center input-text" style="position:relative">

				</div>

				<button class="false-btn" v-show="!messagePass">确认修改</button>
				<button class="true-btn" v-show="messagePass" v-myclick="getCode">确认修改</button>
			</div>
		</div>
	</div>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/url.js"></script>
<script src="../../script/components.js"></script>
<script type="text/javascript" src="../../script/sha1.min.js"></script>
<script type="text/javascript" src="../../script/jquery.js"></script>

<script>
	var vm,
		wx,
		aliTradePlus,
		qq,
		talkingData;
	apiready = function () {
		setBSImg();
		new Vue({
			el: '#blank'
		})
		wx = api.require('wx');
		// setBSImg();
		initApp();
		// doubleBack();
		api.parseTapmode();
		addListeners();
	};

	function initApp() {
		// var isBigImg = Vue.BSImg == 'big';
		vm = new Vue({
			el: '#app',
			data: {
				email: api.pageParam.email ? api.pageParam.email : '',
				password: '',
				code: '',
				appInstalled: {
					wx: true,
				},
				loginMode: 1,
				warn: false,
				messagePass: false,
				messagePass1: false,
				warnText1: '',
				warnText2: '',
				warnText3: '',
			},
			computed: {
			},
			methods: {
				clearMessage: function(){
					this.warn = false;
					this.messagePass = false;
					this.warnText1 = '';
					this.warnText2 = '';
					this.warnText3 = '';
					this.email = '';
					this.password = '';
					this.code = '';

				},
				codeMessage: function (a) {
					this.warnText1 = a;
					this.warn = true;
				},
				selectPage: function (index) {
					this.loginMode = index
				},
				register: function () {
					if (!this.email) {
						vm.warn = true
						vm.warnText1 = '邮箱格式不正确'
						return;
					}
					if (!(/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(this.email))) {
						vm.warn = true
						vm.warnText1 = '请输入正确的邮箱地址'
						return false;
					}
					if (!this.password) {
						vm.warn = true
						vm.warnText3 = '请输入密码'
						return;
					}
					if (this.password.length<6) {
						vm.warn = true
						vm.warnText3 = '请输入六位以上密码'
						return;
					}
					showProgress();
					var data = {
						email: this.email,
						password: this.password,
						jpush_token: getPrefs('jpush_token') || ''
					};
					if (hasPrefs('member_id')) {
						data.member_id = getPrefs('member_id');
					}
					var callback = function (ret) {
						vm.login_init(ret.content, 'email');
					};
					var errback = function (ret) {
						console.log(JSON.stringify(ret))
						vm.warn = true
						vm.warnText3 = '账号或密码错误'
					};
					pinet.post(URL.login, data, callback ,errback);
				},
				login_init: function (user, provider) {
					closeWin('index');
					setPrefs('user', user);
					setPrefs('token', user.token);
					setPrefs('imtoken', user.member_im_token);
					setPrefs('username', user.nickname);
					setPrefs('portrait', user.portrait);
					setPrefs('member_id', user.member_id);
					setPrefs('member_im_id', user.member_im_id);
					setPrefs('level_id', user.level_id);

					api.sendEvent({
						name: 'reLogin'
					});
					vm.clearMessage()
					api.openWin({
						reload: true,
						name: 'index',
						url: '../../index.html',
						hScrollBarEnabled: false,
						slidBackEnabled: false,
					});

				},
				bindAccount: function (params, data, provider) {
					data['jpush_token'] = getPrefs('jpush_token') || '';
					if (hasPrefs('member_id')) {
						data.member_id = getPrefs('member_id');
					}
					var callback = function (ret) {
						if (ret.content.result) {

							vm.login_init(ret.content, provider);
						} else {
							vm.clearMessage()
							openWin('../login/setInfo', params);
						}
					};
					pinet.post(URL.oauthLogin, data, callback);
				},
				login: function () {
					openWin('../login/login');
				},
				// 验证码
				getCode: function () {
					if (!this.email) {
						vm.warn = true
						vm.warnText1 = '请输入正确的邮箱地址'
						return;
					}
					if (!(/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(this.email))) {
						vm.warn = true
						vm.warnText1 = '请输入正确的邮箱地址'
						return false;
					}

					showProgress();
					var data = {
						email: this.email,
						verify_code: this.code,
						password:this.password,
						type: 2,
						jpush_token: getPrefs('jpush_token') || ''
					};
					if (hasPrefs('member_id')) {
						data.member_id = getPrefs('member_id');
					}
					var callback = function (ret) {
						api.toast({
                            msg: '修改密码成功，请重新登录'
                        });
						openWin('../login/login');
					};
					var errback = function (ret) {
					   if(ret.errcode == -408){
							vm.warn = true;
							vm.warnText2 = '验证码错误';
							return;
						}else if(ret.errcode == -409){
							vm.warn = true;
							vm.warnText2 = '验证码已过期';
							return;
						}
						vm.warn = true;
						vm.warnText2 = '验证码错误';
					};
					pinet.post(URL.forgetPwd, data, callback , errback);
				},
			},
			watch: {
				email: function (email) {
					if (!(/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(this.email))) {
							vm.warn = true
							vm.warnText1 = '请输入正确的邮箱'
							return false;
						}else{
							vm.warn = false
							vm.warnText1 = ''
						}
				},
				code: function () {
					if ((/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(this.email)) && vm.code.length == 6) {
						this.messagePass = true
					} else {
						this.warnText1 = ''
						this.warnText2 = ''
						this.warnText3 = ''
						this.messagePass = false
					}
				},
				password: function () {
					if (vm.password.length > 5) {
						vm.warn = false;
						this.warnText3 = '';
					} else {
						vm.warn = true;
						this.warnText3 = '请输入六位以上密码'
					}
				}
			},
		})
	}


	function addListeners() {
		//        api.addEventListener({
		//            name: 'viewappear'
		//        }, function () {
		//            var pageParam = api.pageParam;
		//            if (pageParam && pageParam.from) {
		//                closeWin(pageParam.from);
		//            }
		//        })
	}
	var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
	$(window).on('resize', function () {
		var nowClientHeight = document.documentElement.clientHeight || document.body.clientHeight;
		if (clientHeight > nowClientHeight) {
			$(".wx-login").hide()
		}
		else {
			$(".wx-login").show()
		}
	});
</script>

</html>